

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/myblog/img/fluid.png">
  <link rel="icon" href="/myblog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="ZTY">
  <meta name="keywords" content="">
  
    <meta name="description" content="工作使用kafka学习使用随记~">
<meta property="og:type" content="article">
<meta property="og:title" content="KAFKA基本原理要点">
<meta property="og:url" content="https://zty-f.gitee.io/myblog/2024/03/25/KAFKA%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E8%A6%81%E7%82%B9/index.html">
<meta property="og:site_name" content="zty-f">
<meta property="og:description" content="工作使用kafka学习使用随记~">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s3.bmp.ovh/imgs/2024/03/30/a67a23091211c5a9.png">
<meta property="article:published_time" content="2024-03-25T01:22:04.000Z">
<meta property="article:modified_time" content="2024-12-28T02:09:42.874Z">
<meta property="article:author" content="ZTY">
<meta property="article:tag" content="学习">
<meta property="article:tag" content="kafka">
<meta property="article:tag" content="中间件">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://s3.bmp.ovh/imgs/2024/03/30/a67a23091211c5a9.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>KAFKA基本原理要点 - zty-f</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/myblog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/myblog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/myblog/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_3799348_11m20qbqwhmo.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"zty-f.gitee.io","root":"/myblog/","version":"1.9.3","typing":{"enable":true,"typeSpeed":150,"cursorChar":"_","loop":true,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/myblog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/myblog/js/utils.js" ></script>
  <script  src="/myblog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/myblog/">
      <strong>思前想后</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                魔盒
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" href="/myblog/archives/">
                    <i class="iconfont icon-archive-fill"></i>
                    归档
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/myblog/categories/">
                    <i class="iconfont icon-yingyong"></i>
                    分类
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/myblog/tags/">
                    <i class="iconfont icon-tags-fill"></i>
                    标签
                  </a>
                
              </div>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" target="_blank" rel="noopener" href="https://github.com/zty-f">
                <i class="iconfont icon-GitHub"></i>
                
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/myblog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="KAFKA基本原理要点"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        ZTY
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2024-03-25 09:22" pubdate>
          2024年3月25日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          2.2k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          18 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">KAFKA基本原理要点</h1>
            
            
              <div class="markdown-body">
                
                <h3 id="KAFKA基本原理要点"><a href="#KAFKA基本原理要点" class="headerlink" title="KAFKA基本原理要点"></a>KAFKA基本原理要点</h3><ol>
<li><p>KAFKA作为数据连接层，以集群的方式运行，可以自由伸缩，持续处理大型的数据流。</p>
</li>
<li><p>KAFKA的消息通过主题进行分类。</p>
</li>
<li><p>主题可以被分为若干个分区，一个分区就是一个提交日志。</p>
<ol>
<li>消息以追加的方式写入分区，然后以先入先出的顺序读取。</li>
<li>一个主题包含多个分区，无法在整个topic上保证消息的顺序性，但可以保证消息在单个分区上的顺序性</li>
<li>KAKFA可以通过分区来实现数据的伸缩性和冗余性</li>
<li>多个分区可以分布在不同的服务器上，因此可以提供比单服务器更强大的性能<img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/tYQ3AT9LKLDebhZP.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></li>
</ol>
</li>
<li><p>KAFKA的客户端主要分为：生产者和消费者；</p>
<ol>
<li>数据集成用的KAFKA Connect API </li>
<li>流式处理的KAFKA Stream &#x3D;&#x3D;&gt; Flink</li>
</ol>
</li>
<li><p>生产者创建消息</p>
<ol>
<li>生产者在默认情况下把消息均衡地分布到主题的所有分区上，而并不关心特定消息会被写到哪个分区</li>
<li>生产者会把消息直接写到指定的分区。这通常是通过消息键和分区器来实现的<ol>
<li>分区器为键生成一个散列值，并将其映射到指定的分区上。这样可以保证包含同一个键的消息会被写到同一个分区上。</li>
<li>生产者也可以使用自定义的分区器，根据不同的业务规则将消息映射到分区。</li>
</ol>
</li>
</ol>
</li>
<li><p>消费者读取消息</p>
<ol>
<li>消费者订阅一个或多个主题，并按照消息生成的顺序读取消息。</li>
<li>消费者通过检查消息的偏移量来区分已经读取过的消息。</li>
</ol>
</li>
<li><p>偏移量</p>
<ol>
<li>偏移量是另一种元数据，它是一个不断递增的整数值，在创建消息时，Kafka会把它添加到消息里。</li>
<li>在给定的分区里，每个消息的偏移量都是唯一的。</li>
<li>消费者把每个分区最后读取的消息偏移量保存在 <strong>Zookeeper</strong> 或 Kafka 上，如果消费者关闭或重启，它的读取状态不会丢失。</li>
</ol>
</li>
<li><p>消费者群组</p>
<ol>
<li>由多个消费者组成，群组保证每个分区只能被一个消费者使用。</li>
<li><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/QSrhNqa1pPXK2wYS.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></li>
<li>消费者与分区之间的映射通常被称为消费者对分区的所有权关系。</li>
</ol>
</li>
<li><p>broker 和集群<br><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/J67PCiDH8rW9Cwwo.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></p>
<ol>
<li>一个独立的 Kafka 服务器被称为 broker。</li>
<li>作用1：broker 接收来自生产者的消息，为消息设置偏移量，并提交消息到磁盘保存。</li>
<li>作用2：broker 为消费者提供服务，对读取分区的请求作出响应，返回已经提交到磁盘上的消息</li>
<li>broker 是集群的组成部分。每个集群都有一个 broker 同时充当了集群控制器的角色（自动从集群的活跃成员中选举出来）<a target="_blank" rel="noopener" href="https://raft.github.io/">https://raft.github.io/</a></li>
<li><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/CZcD3LCck1DUoL5B.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></li>
<li>一个 Kafka集群需要多少个 broker 取决于以下几个因素。</li>
<li>首先，需要多少磁盘空间来保留数据，以及单个 broker 有多少空间可用。如果整个集群需要保留 10TB 的数据，每个broker 可以存储 2TB，那么至少需要 5 个 broker。</li>
<li>一个分区可以分配给多个 broker，这个时候会发生分区复制。这种复制机制为分区提供了消息冗余，如果有一个 broker 失效，其他 broker 可以接管领导权。<img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/e6caveYD96cgcHh9.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></li>
<li>保留消息：Kafka 的一个重要特性。Kafka broker 默认的消息保留策略是这样的：要么保留一段时间（比如 7 天），要么保留到消息达到一定大小的字节数（比如 1GB）。当消息数量达到这些上限时，旧消息就会过期并被删除。<a target="_blank" rel="noopener" href="https://redis.io/topics/lru-cache">https://redis.io/topics/lru-cache</a></li>
</ol>
</li>
<li><p>KAFKA的一些特性</p>
<ol>
<li>多生产者</li>
<li>多消费者</li>
<li>基于磁盘的数据存储</li>
<li>伸缩性</li>
<li>高性能消息流处理工具</li>
</ol>
</li>
<li><p>生产者写数据</p>
<ol>
<li>向KAFKA发送消息的主要步骤<br><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/fvWEejvgWs2PU0Q3.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></li>
<li>ProducerRecord 对象需要包含目标主题和要发送的内容。我们还可以指定键或分区。</li>
<li>在发送 ProducerRecord 对象时，生产者要先把键和值对象序列化成字节数组，这样它们才能够在网络上传输。</li>
<li>数据被传给分区器。如果之前在 ProducerRecord 对象里指定了分区，那么分区器 就不会再做任何事情，直接把指定的分区返回。如果没有指定分区，那么分区器会根据 ProducerRecord 对象的键来选择一个分区。</li>
<li>选好分区以后，生产者就知道该往哪个主题和分区发送这条记录了。紧接着，这条记录被添加到一个记录批次里，这个批次里的所有消息会被发送到相同的主题和分区上。有一个独立的线程负责把这些记录批次发送到相应的broker 上</li>
<li>服务器在收到这些消息时会返回一个响应。如果消息成功写入 Kafka，就返回一个 RecordMetaData 对象，它包含了主题和分区信息，以及记录在分区里的偏移量。如果写入失败，则会返回一个错误。生产者在收到错误之后会尝试重新发送消息，几次之后如果还是失败，就返回错误信息。</li>
</ol>
</li>
<li><p>发送消息的方式</p>
<ol>
<li>发送并忘记(fire and forget)<br>把消息发送给服务器，但并不关心它是否正常到达。因为 Kafka 是高可用的，而且生产者会自动尝试重发。不过，使用这种方式有时候 也会丢失一些消息。<ol start="2">
<li>同步发送<br>明确的等待消息是否发送成功</li>
<li>异步发送<br> 指定一个回调函数，服务器在返回响应时调用该函数。</li>
</ol>
</li>
</ol>
</li>
<li><p>消费者消费</p>
</li>
</ol>
<p>1.消费者组</p>
<p><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/08siTUy8BJktuKvE.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></p>
<p><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/7n57r2jz9Lmwhafp.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></p>
<p><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/49dF7U7cKsa5mH0B.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></p>
<p><img src="https://yach-doc-shimo.zhiyinlou.com/uploader/f/wg1hi4h2K5tKCMAM.png?accessToken=eyJhbGciOiJIUzI1NiIsImtpZCI6ImRlZmF1bHQiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE3MDk2MjYzODQsImZpbGVHVUlEIjoiMGwzTlZiV29uNkNsREUzUiIsImlhdCI6MTcwOTYyNjA4NCwiaXNzIjoidXBsb2FkZXJfYWNjZXNzX3Jlc291cmNlIiwidXNlcklkIjozNTExNDI5fQ._NbzGkvi2YSKxtYb-bC4bmcJe0_fFp66QL-QaP07I0g" srcset="/myblog/img/loading.gif" lazyload alt="img"></p>
<ol start="2">
<li><p>再均衡</p>
<p>2.1当一个消费者被<strong>关闭或发生崩溃时</strong>，它就离开群组，原本由它读取的分区将由群组里的其他消费者来读取。在主题发生变化时，比如管理员添加了新的分区，会发生分区重分配。</p>
<p>2.2 分区的所有权从一个消费者转移到另一个消费者，这样的行为被称为<strong>再均衡</strong>。</p>
</li>
<li><p>消费者通过向被指派为群组协调器的 broker（不同的群组可以有不同的协调器）发送心跳来维持它们和群组的从属关系以及它们对分区的所有权关系。</p>
</li>
<li><p>如果消费者停止发送心跳的时间足够长，会话就会过期，群组协调器认为它已经死亡，就会触发一次再均衡。</p>
</li>
</ol>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/myblog/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/" class="category-chain-item">云原生</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/myblog/tags/%E5%AD%A6%E4%B9%A0/">#学习</a>
      
        <a href="/myblog/tags/kafka/">#kafka</a>
      
        <a href="/myblog/tags/%E4%B8%AD%E9%97%B4%E4%BB%B6/">#中间件</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>KAFKA基本原理要点</div>
      <div>https://zty-f.gitee.io/myblog/2024/03/25/KAFKA基本原理要点/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>ZTY</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2024年3月25日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2024年12月28日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/myblog/2024/03/30/%E6%99%AE%E9%80%9AOR%E5%94%AF%E4%B8%80%E7%B4%A2%E5%BC%95/" title="普通OR唯一索引">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">普通OR唯一索引</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/myblog/2024/03/05/work_record/" title="WorkNormalRecord">
                        <span class="hidden-mobile">WorkNormalRecord</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  <article id="comments" lazyload>
    
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"wLiqWYFHh2NEnXVcULmB4KWQ-gzGzoHsz","appKey":"GSfJMcM0GcCzp1HDNXJfd9Bt","path":"window.location.pathname","placeholder":"欢迎大家积极评论~  支持Markdown格式~","avatar":"wavatar","meta":["nick","mail","link"],"requiredFields":["nick","mail"],"pageSize":10,"lang":"zh-CN","highlight":true,"recordIP":true,"serverURLs":"https://wliqwyfh.lc-cn-n1-shared.com","emojiCDN":null,"emojiMaps":null,"enableQQ":true},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


  </article>


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
      <div class="col-lg-7 mx-auto nopadding-x-md">
        <div class="container custom mx-auto">
          <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"> <script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js"></script> <meting-js server="netease"  type="playlist"  id="7708362143" fixed="true"  mini="true" order="list" loop="all" preload="auto" list-folded="true" autoplay="true" theme="red"> </meting-js>
        </div>
      </div>
    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://github.com/zty-f" target="_blank" rel="nofollow noopener"><span>Copyright &copy;</span></a> <a href="http://www.zty-f.fun/" target="_blank" rel="nofollow noopener"><span>zty-f</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      蜀ICP备2022002077号-1
    </a>
  </span>
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/myblog/js/events.js" ></script>
<script  src="/myblog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/myblog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/myblog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/myblog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
